package com.safe.ele.controller;




import com.safe.ele.entity.IType;
import com.safe.ele.service.intf.ITypeService;
import com.safe.ele.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.Page;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
/**
 * @program: springboot
 * @description: 十一组后端源码
 * @author: Feri(十一组)
 * @create: 2021-01-09 17:39:00
 */
@RestController
@RequestMapping("api/iType/")
@Api(tags = "实现IType各种操作")
public class ITypeController{
    /*
    *注入业务逻辑层对象*/
    @Autowired
    private ITypeService service;
    /*
    * 新增内容*/
    @ApiOperation(value = "实现新增",notes = "实现新增")
    @PostMapping("IType.save.do")
    public R save(@RequestBody IType iType){
       return service.save(iType);
    }
    /*
    * 查询 所有数据*/
    @ApiOperation(value = "实现全部查询",notes = "实现全部查询")
    @GetMapping("IType.all.do")
    public R  all( String tname){
        List<IType> iTypes = service.queryAll(tname);
        return R.ok(iTypes);


//       Map<String, Object> map = new HashMap<>();
//                   //状态吗
//                   map.put("code", 0);
//                   //没有错误信息
//                   map.put("msg", "");
//                   //总条数
//                   map.put("count", ((Page) list).getTotal());
//                   //查询分页后数据
//                   map.put("data", list);
//                   //返回前段
//                   return map;
    }


    /*
     * 根据ID查询数据*/
     @ApiOperation(value = "根据ID查询数据",notes = "根据ID查询数据")
     @GetMapping("IType.selectById.do")
     public R selectById(IType iType){
       return service.selectById(iType);
     }

    /*
     * 删除内容*/
     @ApiOperation(value = "实现删除",notes = "实现删除")
     @PostMapping("IType.del.do")
     public R del(@RequestBody IType iType){
        return service.DelAll(iType);
     }

     /*
     * 跟新内容*/
     @ApiOperation(value = "实现跟新",notes = "实现跟新")
     @PostMapping("IType.updateById.do")
     public R updateById(@RequestBody IType iType){
         return service.updateById(iType);
      }

     /*
     * 模糊查询*/
     @ApiOperation(value = "实现模糊查询",notes = "实现模糊查询")
     @PostMapping("IType.selectMhcx.do")
     public Map<String, Object> selectMhcx(@RequestBody IType iType,Integer page, Integer limit){
      List<IType> list =  service.selectMhcx(iType,page, limit);
      Map<String, Object> map = new HashMap<>();
                        //状态吗
                        map.put("code", 0);
                        //没有错误信息
                        map.put("msg", "");
                        //总条数
                        map.put("count", ((Page) list).getTotal());
                        //查询分页后数据
                        map.put("data", list);
                        //返回前段
                        return map;

       }

     /*
     * 批量删除*/
     @ApiOperation(value = "实现批量删除",notes = "实现批量删除")
     @PostMapping("IType.deleteByIds.do")
     public R deleteByIds(@RequestBody IType iType,String ids){
         return service.deleteByIds(iType,ids);
      }

}